

package com.hazelcast.jet.core.function;

import com.hazelcast.internal.util.ExceptionUtil;

import java.io.Serializable;

/**
 * Represents a specialization of {@link java.util.function.BiFunction} where
 * the second argument is a {@code long}.
 *
 * @param <T> the type of the first argument to the function
 * @param <R> the type of the result of the function
 * @since Jet 3.0
 */
@FunctionalInterface
public interface ObjLongBiFunction<T, R> extends Serializable {

    /**
     * Exception-declaring version of {@link ObjLongBiFunction#apply}.
     */
    R applyEx(T t, long u) throws Exception;

    /**
     * Applies this function to the given arguments.
     *
     * @param t the first function argument
     * @param u the second function argument
     * @return the function result
     */
    default R apply(T t, long u) {
        try {
            return applyEx(t, u);
        } catch (Exception e) {
            throw ExceptionUtil.sneakyThrow(e);
        }
    }
}
